﻿Imports System.Text.RegularExpressions

Public Class BLLSolicitante
    Dim objDAO As DALSolicitante
    Private codigo As Integer
    Private nome As String
    Private empresa As String
    Private telefone As Integer
    Private celular As String
    Private cidade As String
    Private email As String
    Private obs As String
    Private pessoa As String

#Region "Propriedades"
    Public Property pobs() As String
        Get
            Return Me.obs
        End Get
        Set(ByVal value As String)
            Me.obs = value
        End Set
    End Property
    Public Property pemail() As String
        Get
            Return Me.email
        End Get
        Set(ByVal value As String)
            Me.email = value
        End Set
    End Property

    Public Property pcidade() As String
        Get
            Return Me.cidade
        End Get
        Set(ByVal value As String)
            Me.cidade = value
        End Set
    End Property

    Public Property ppessoa As String
        Get
            Return Me.pessoa
        End Get
        Set(ByVal value As String)
            Me.pessoa = value
        End Set
    End Property
    Public Property pcelular As String
        Get
            Return Me.celular
        End Get
        Set(ByVal value As String)
            Me.celular = value
        End Set
    End Property
    Public Property ptelefone As Integer
        Get
            Return Me.telefone
        End Get
        Set(ByVal value As Integer)
            Me.telefone = value
        End Set
    End Property
    Public Property pCodigo As Integer
        Get
            Return Me.codigo
        End Get
        Set(ByVal value As Integer)
            Me.codigo = value
        End Set
    End Property

    Public Property pnome As String
        Get
            Return Me.nome
        End Get
        Set(ByVal value As String)
            Me.nome = value
        End Set
    End Property


    Public Property pempresa As String
        Get
            Return Me.empresa
        End Get
        Set(ByVal value As String)
            Me.empresa = value
        End Set
    End Property

#End Region
#Region "Métodos"

    Sub New(ByVal codigo As Integer, ByVal descricao As String)
        carrega(codigo, descricao)
    End Sub
    Sub New()

    End Sub

    Sub carrega(ByVal codigo As Integer, ByVal descricao As String)
        Dim tab As DataTable
        Try
            objDAO = New DALSolicitante
            tab = objDAO.localizar(codigo, descricao)
            If (tab.Rows.Count > 0) Then
                Me.codigo = tab.Rows(0)("agd_codigo").ToString
                Me.nome = tab.Rows(0)("agd_nome").ToString
                Me.pessoa = tab.Rows(0)("agd_desc").ToString
            End If
        Catch ex As Exception
            Throw ex
        Finally
            objDAO = Nothing

        End Try
    End Sub
    Function Inserir() As Integer
        Dim ret As Boolean
        Try
            objDAO = New DALSolicitante
            If (ValidaDuplicata(nome, 0)) Then
                ret = objDAO.Inserir(Me.nome, Me.empresa, Me.telefone, Me.celular, Me.cidade, Me.email, Me.obs)
            Else
                ret = False
            End If
        Catch ex As Exception
            Throw ex
        Finally
            objDAO = Nothing
        End Try
        Return ret
    End Function
    Function ValidaDuplicata(ByVal Solicitante As String, ByVal codigo As String) As Boolean
        Dim ret As Boolean
        Dim tab As DataTable
        Try
            objDAO = New DALSolicitante
            tab = objDAO.ValidaDuplicata(Solicitante, codigo)
            If tab.Rows.Count = 0 Then
                ret = True
            Else
                ret = False
            End If
        Catch ex As Exception
            Throw ex
        Finally
        End Try
        Return ret
    End Function
    Function Alterar() As Boolean
        Dim ret As Boolean
        Try
            objDAO = New DALSolicitante
            If (ValidaDuplicata(nome, codigo)) Then
                ret = objDAO.Alterar(Me.nome, Me.empresa, Me.telefone, Me.celular, Me.codigo, Me.cidade, Me.email, Me.obs)
            Else
                ret = False
            End If
        Catch ex As Exception
            Throw ex
        Finally
            objDAO = Nothing
        End Try
        Return ret
    End Function


    Function Excluir(ByVal Codigo As Integer) As Integer
        Dim ret As Integer = 0
        Dim tab As DataTable
        Try
            objDAO = New DALSolicitante
            tab = objDAO.ValidaExclusao(Codigo, 4)
            If tab.Rows.Count = 0 Then
                objDAO.Excluir(Codigo)
                ret = 1
            Else
                objDAO.ExcluirUpdate(Codigo)
                ret = 2
            End If
        Catch ex As Exception
            Throw ex
        Finally
            tab = Nothing
            objDAO = Nothing
        End Try
        Return ret
    End Function

    'Function localizar(ByVal nome As String) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAO = New DALSolicitante
    '        tab = objDAO.localizar(nome)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAO = Nothing
    '    End Try
    '    Return tab
    'End Function
    Function localizar(ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Try
            objDAO = New DALSolicitante
            tab = objDAO.localizar(codigo)
        Catch ex As Exception
            Throw ex
        Finally
            objDAO = Nothing
        End Try
        Return tab
    End Function
    Function Localizar(TP As Integer, ByVal Nome As String) As DataTable
        Dim tab As DataTable
        Try
            objDAO = New DALSolicitante
            tab = objDAO.localizar(TP, Nome)
        Catch ex As Exception
            Throw ex
        Finally
            objDAO = Nothing
        End Try
        Return tab
    End Function
    'Function localizarTudo(ByVal codigo As Integer) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAO = New DALSolicitante
    '        tab = objDAO.localizarTudo(codigo)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAO = Nothing
    '    End Try
    '    Return tab
    'End Function
#End Region
End Class
